package com.example.mydesignmodule.factory;

/**
 * @author tgw
 * @date 2021/2/26
 * @describe
 */
public class CarFactory {

    public static <T extends Car> T createdCar(Class<T> cla) {
        Car car = null;
        try {
            car = (Car) Class.forName(cla.getName()).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return (T) car;
    }

    public static <T extends CarType> T createdCarType(Class<T> cla) {
        CarType carType = null;
        try {
            carType = (CarType) Class.forName(cla.getName()).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return (T) carType;
    }
}
